package com.mobilebsc.app;

import java.util.ArrayList;

import com.mobilebsc.datatype.KPI;
import com.mobilebsc.datatype.Perspective;
import com.mobilebsc.datatype.StrategicGoal;
import com.mobilebsc.datatype.WeakSignal;

public class DataManager
{
    //private static String TAG = "DataManager";
	private ArrayList<Perspective> perspectives;

    public void setPerspectives(ArrayList<Perspective> perspectives)
    {
        this.perspectives = perspectives;
    }

    public void loadData(int perspectiveId)
    {
        if (perspectiveId == -1)
        {
            perspectives = loadPerspectives();
        }
        else
        {
            perspectives = loadPerspectiveById(perspectiveId); 
        }
    }
    
    private ArrayList<Perspective> loadPerspectives()
    {
        ArrayList<Perspective> perspectives = new ArrayList<Perspective>();
		
        perspectives.add(new Perspective(0, "Perspective 0", "description 0"));
        perspectives.add(new Perspective(1, "Perspective 1", "description 1"));
        
        for (Perspective p: perspectives)
        {
            p.setStrategicGoals(loadStrategicGoalsByPerspective(p.getId()));
        }
        
        return perspectives;
    }
    
    private ArrayList<Perspective> loadPerspectiveById(int perspectiveId)
    {
        ArrayList<Perspective> perspectives = new ArrayList<Perspective>();
        
        perspectives.add(new Perspective(perspectiveId, "Perspective "+perspectiveId, "description "+perspectiveId));
        
        for (Perspective p: perspectives)
        {
            p.setStrategicGoals(loadStrategicGoalsByPerspective(p.getId()));
        }
        
        return perspectives;
    }
    
    public ArrayList<Perspective> getPerspectives()
    {
        return perspectives;
    }
    
    private ArrayList<StrategicGoal> loadStrategicGoalsByPerspective(int perspectiveId)
    {
    	ArrayList<StrategicGoal> strategicGoals = new ArrayList<StrategicGoal>();
        
        strategicGoals.add(new StrategicGoal(perspectiveId * 10 + 0, "StrategicGoal " + perspectiveId + "0", "description 0"));
        strategicGoals.add(new StrategicGoal(perspectiveId * 10 + 1, "StrategicGoal " + perspectiveId + "1", "description 1"));
        
        for (StrategicGoal sg: strategicGoals)
        {
            sg.setKpis(loadKPIsByStrategicGoal(sg.getId()));
        }
        
        return strategicGoals;
    }
    
    private ArrayList<KPI> loadKPIsByStrategicGoal(int strategicGoalId)
    {
        ArrayList<KPI> kpis = new ArrayList<KPI>();
        
        kpis.add(new KPI(strategicGoalId * 10 + 0, "KPI " + strategicGoalId + "0", "description 0", 10, 10, 10));
        kpis.add(new KPI(strategicGoalId * 10 + 1, "KPI " + strategicGoalId + "1", "description 1", 5, 3, 3));
        kpis.add(new KPI(strategicGoalId * 10 + 2, "KPI " + strategicGoalId + "2", "description 2", 12, 2, 2));
        kpis.add(new KPI(strategicGoalId * 10 + 3, "KPI " + strategicGoalId + "3", "description 3", 5, 5, 5));
        
        for (KPI k: kpis)
        {
            k.setWeakSignals(loadWeakSignalsByKPI(k.getId()));
        }
        
        return kpis;
    }
    
    private ArrayList<WeakSignal> loadWeakSignalsByKPI(int kpiId)
    {
        ArrayList<WeakSignal> weakSignals = new ArrayList<WeakSignal>();
        
        weakSignals.add(new WeakSignal(kpiId * 10 + 0, "WeakSignal " + kpiId + "0", "description 0", "Test"));
        weakSignals.add(new WeakSignal(kpiId * 10 + 1, "WeakSignal " + kpiId + "1", "description 1", "Test"));
        weakSignals.add(new WeakSignal(kpiId * 10 + 2, "WeakSignal " + kpiId + "2", "description 2", "Test"));
        weakSignals.add(new WeakSignal(kpiId * 10 + 3, "WeakSignal " + kpiId + "3", "description 3", "Test"));
        
        return weakSignals;
    }
}